package m.jclecai.com.view.klpk;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import m.jclecai.com.R;
import m.jclecai.com.bean.klpk.bean.PokerBean;


/**
 * Created by andy on 2017/7/12.
 *
 * 这里是poker机选的一个效果的实现类
 */

public class RandomPoker extends FrameLayout {

    int[] type={R.drawable.pk_effect_poker_spade_type,R.drawable.pk_effect_poker_heart_type
            ,R.drawable.pk_effect_poker_club_type,R.drawable.pk_effect_poker_box_type};

    int[] logo={R.drawable.pk_effect_poker_spade_logo,R.drawable.pk_effect_poker_heart_logo
            ,R.drawable.pk_effect_poker_club_logo,R.drawable.pk_effect_poker_box_logo
            ,R.drawable.pk_effect_poker_j,R.drawable.pk_effect_poker_q,R.drawable.pk_effect_poker_k
            };



    private TextView mTvPokerText;
    private ImageView mIvPokerType;
    private ImageView mIvPokerLogo;

    public RandomPoker(Context context) {
        this(context,null);
    }

    public RandomPoker(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public RandomPoker(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        View view = View.inflate(context, R.layout.layout_effect_poker, this);
        mTvPokerText = ((TextView) view.findViewById(R.id.tv_poker_text));
        mIvPokerType = ((ImageView) view.findViewById(R.id.iv_poker_type));
        mIvPokerLogo = ((ImageView) view.findViewById(R.id.iv_poker_logo));

        Typeface typeface = Typeface.createFromAsset(context.getAssets(), "typewriter.ttf");
        mTvPokerText.setTypeface(typeface);
    }

    public void setPokerLogo(int resId){
        mIvPokerLogo.setImageResource(resId);
    }
    public void setPokerType(int resId){
     mIvPokerType.setImageResource(resId);
    }

    public void setPokerText(String string){
        mTvPokerText.setText(string);
    }

    public void setPoker(PokerBean pokerBean){

        int pokerType=0;
        int pokerLogo=0;

        if (pokerBean.getCategory()== PokerBean.Category.box) {
            //方块
            pokerType=type[3];
            pokerLogo=logo[3];


            mTvPokerText.setTextColor(getContext().getResources().getColor(R.color.klpk_text_red_color));
        }else if(pokerBean.getCategory()==PokerBean.Category.hearts){
            //红桃；
            pokerType=type[1];
            pokerLogo=logo[1];

            mTvPokerText.setTextColor(getContext().getResources().getColor(R.color.klpk_text_red_color));

        }else if(pokerBean.getCategory()==PokerBean.Category.pulm_blossomm){
            //梅花；
            pokerType=type[2];
            pokerLogo=logo[2];
            mTvPokerText.setTextColor(getContext().getResources().getColor(R.color.color_333333));
        }else if(pokerBean.getCategory()== PokerBean.Category.spades){
            //黑桃；
            pokerType=type[0];
            pokerLogo=logo[0];
            mTvPokerText.setTextColor(getContext().getResources().getColor(R.color.color_333333));
        }

        if(pokerBean.getNumStr().equals("J")){
            pokerLogo=logo[4];
        } else if (pokerBean.getNumStr().equals("Q")) {
            pokerLogo=logo[5];
        }else if(pokerBean.getNumStr().equals("K")){
            pokerLogo=logo[6];
        }

        //这里是设置poker的一个值；
        setPokerText(pokerBean.getNumStr());
        setPokerType(pokerType);
        setPokerLogo(pokerLogo);
    }
}
